<template>
	<view class="form-container">
		<!-- 绑定房源信息 -->
		<form @submit="formSubmit" @reset="formReset">
			<view class="form-item">
				<image src="../../static/house_info_icons/house_location.png" class="icon"></image>
				<view class="title">地产位置</view>
				<input class="form-input" name="address" placeholder="请输入地产位置" placeholder-style="text-ali" />
			</view>
			<view class="form-item">
				<image src="../../static/house_info_icons/house_name.png" class="icon"></image>
				<view class="title">地产名称</view>
				<input class="form-input" name="estateName" placeholder="请输入地产名称" />
			</view>
			<view class="form-item">
				<image src="../../static/house_info_icons/project_name.png" class="icon"></image>
				<view class="title">项目名称</view>
				<input class="form-input" name="projectName" placeholder="请输入项目名称" />
			</view>
			<view class="form-item">
				<image src="../../static/house_info_icons/building.png" class="icon"></image>
				<view class="title">楼栋</view>
				<input class="form-input" name="building" type="number" placeholder="请选择楼栋" />
			</view>
			<view class="form-item">
				<image src="../../static/house_info_icons/cell.png" class="icon"></image>
				<view class="title">单元</view>
				<input class="form-input" name="unit" type="number" placeholder="请选择单元" />
			</view>
			<view class="form-item">
				<image src="../../static/house_info_icons/house_num.png" class="icon"></image>
				<view class="title">房号</view>
				<input class="form-input" name="num" type="number" placeholder="请选择房号" />
			</view>
			<view class="form-item">
				<image src="../../static/house_info_icons/house_type.png" class="icon"></image>
				<view class="title">房型</view>
				<input class="form-input" name="estateType" placeholder="请选择房型" />
			</view>
			<view class="form-item">
				<button class="form-btn" form-type="submit" @click="push()">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		name: "create-house-form",
		data() {
			return {
				address: "",
				building: 0,
				estateId: "",
				estateName: "",
				estateType: "",
				num: 0,
				projectName: "",
				unit: 0,
			};
		},
		methods: {
			formSubmit: function(e) {
				const data = e.detail.value
				data.building = Number(e.detail.value.building)
				data.num = Number(e.detail.value.num)
				data.unit = Number(e.detail.value.unit)
				this.bindHouse(data)
			},
			async bindHouse(data) {
				const {
					data: res
				} = await uni.$http.post(uni.$http.baseURL + '/realEstate/bind', data)
				console.log(res)
				if(res.message == '成功'){
					uni.$showMsg('绑定成功！','success')
					this.$emit('click')
				}
			},
			push() {
				this.$emit('click')
			}
		}
	}
</script>

<style lang="scss">
	.form-container {
		margin: 83rpx 30rpx 80rpx 30rpx;
		background: #FFFFFF;
		width: 690rpx;
		height: 700rpx;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		flex-direction: column;

		.form-item {
			height: 100rpx;
			display: flex;
			flex-direction: row;
			align-items: center;

			.icon {
				margin-left: 21rpx;
				width: 26rpx;
				height: 25rpx;
			}

			.title {
				color: #333333;
				font-weight: bold;
				font-size: 28rpx;
				margin-left: 15rpx;
			}

			.form-input {
				margin-right: 15rpx;
				text-align: right;
			}

			.form-btn {
				height: 88rpx;
				width: 100%;
				margin-top: 100rpx;
				background: linear-gradient(90deg, #E62129 0%, #BA000A 100%);
				box-shadow: 0rpx 5rpx 15rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 44rpx;
			}
		}
	}
</style>
